<?php defined('API') or exit('http://admin.medtrib.cn');?>
<?php
if(!is_supper()){die('只有超级管理员才可对分类进行操作');}
$op = I($_GET['op']);
$type = I($_GET['type']);
$_VAL = I($_POST);
$aid = $_VAL['aid'];
$uid = session('id'); //操作者id
if($type=='do'){
	$val = $_VAL['localUrl'];
	$sql = "select count(1)ct from cate_setting where aid='{$aid}' and uid='{$uid}' and `type`=0";
	$count = select($sql);
	echo $count;
	if($count && $count['ct']>0){
		$sql = "update cate_setting set val='{$val}' where aid='{$aid}' and uid='{$uid}' and `type`=0";
	}else{
		$sql = "insert into cate_setting(aid,uid,type,val)values({$aid},{$uid},0,'{$val}')";
	}
	
	$ret = update($sql);
	if($ret){
		go(U());
	}else{
		echo '<div class="alert alert-danger" role="alert"><span class="glyphicon glyphicon-info-sign" aria-hidden="true"></span> 修改失败</div>';
	}
}else{
	$sql = "select * from cate where aid='{$aid}'";
	$info = find($sql);
	$sql = "select val from cate_setting where aid='{$aid}' and uid='{$uid}' and `type`=0";
	$val = find($sql);
}


?>
<div style="border:1px solid #ddd">
        <div style="background:#f5f5f5;padding:20px;position:relative">
            <h4><?php echo $info['cname'] ?></h4>
            <div>
                <form action="?act=setting&type=do" method="post">
                	<input type="hidden" name="aid" value="<?php echo $aid ?>"/>
                    <div class="form-group">
                    	<label>本机测试地址</label>
                        <input type="text" class="form-control" name="localUrl" required="required" placeholder="本机测试地址" value="<?php echo $val['val'] ?>">
                    </div>
                    <button class="btn btn-success" name="op" value="edit">Submit</button>
                </form>
            </div>
        </div>
</div>
